#	 Copyright 2012, 2012 Noel Warren

#    This file is part of MiniVistii.
#    MiniVistii is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    MiniVistii is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.

#    You should have received a copy of the GNU Lesser General Public License
#    along with MiniVistii.  If not, see <http://www.gnu.org/licenses/>.

module Toolbox
	def self.normalize(x)
		decimals = 2
		factor = 10**decimals
		return ((x.to_mm * factor).round.to_f / factor).to_s
	end
	
	def self.face(vector)
		vector.normalize!
		if vector == Geom::Vector3d.new(0,-1,0)
			return 1
		elsif vector == Geom::Vector3d.new(0,1,0)
			return 2
		elsif vector == Geom::Vector3d.new(1,0,0)
			return 3
		elsif vector == Geom::Vector3d.new(-1,0,0)
			return 4
		elsif vector == Geom::Vector3d.new(0,0,-1)
			return 5
		elsif vector == Geom::Vector3d.new(0,0,1)
			return 6
		else
			return nil
		end
	end
	
	def self.breakUp(array, length = CNC.maxLines)
		result = []
		array.each_index{|index|
			q, m = index.divmod length
			result[q] = [] if m == 0
			result[q].push array[index]
		}
		return result
	end
end
puts "Toolbox OK"